<template>
	<view class="page-body">
		<view class="page-body-box">
			 <view class="info-box">
				 <view class="info-row-text">姓　 名</view>
				 <view class="info-row-input"><input type="text" value="" maxlength="10"  v-model="userInfo.contactName" /></view>
			 </view>
			 <view class="info-box">
			 	<view class="info-row-text">手 机 号</view>
			 	<view class="info-row-input"><input type="text" maxlength="12" value="" v-model="userInfo.contactMobileNo" /></view>
			 </view>
			 <view class="info-box">
			 	<view class="info-row-text">公司名称</view>
			 	<view class="info-row-input"><input type="text" placeholder="选填" maxlength="25" value=""  v-model="userInfo.companyName"  /></view>
			 </view>
			 <wx-form-id :saveData="saveUser" :getFormId="saveFormId" :btnClass="btnClass" :btnSubmitClass="btnSubmitClass" btnName="保存"></wx-form-id>
			 	<!--<button type="" @tap="saveUser">{{optionLabel}}</button>-->
		</view>
		</view>
</template>

<script>
	import validate from '@/common/graceChecker.js'
	import { validateTips } from '@/common/checkerMessage.js'
	import publicMethod from '@/common/publicMethod.js'; 
	import enums from '@/common/sysEnum.js';
	import api from '@/common/api.js';
    import wxFormId from '@/components/wxFromId.vue';
	export default {
    components: {
      wxFormId
    },
		data() {
			return {
				optionLabel: '保存',
				userInfo:{
				  contactName:'',
				  contactMobileNo:'',
				  companyName:''
				},
				btnClass:['page-userinfo-btn-box'],
				btnSubmitClass:['page-userinfo-btn-submit-box']
			};
		},
		onLoad() {
		   Object.assign(this.userInfo, this.$store.getters.getUserInfo);
		},
		methods:{
			saveFormId(e){
				let that = this;
				that.commonSaveFormId(e)//保存表单FormId
			},
			saveUser: function (e) {
				let that = this;

				if (!this.userInfo.contactName || this.userInfo.contactName === '') {
					that.showToast('请填写姓名')
					return;
				}
				if (!this.userInfo.contactMobileNo || this.userInfo.contactMobileNo === '') {
					that.showToast('请填写联系人电话')
					return;
				}
				
				if (!validate.checkContactNumber({
						message: validateTips.FILL_RIGHT_CONTACT_PHONE,
						nullAble: true
					}, this.userInfo.contactMobileNo, that.showError)) {
					return;
				}
				var data={
					contactName: this.userInfo.contactName,
					contactMobileNo: this.userInfo.contactMobileNo,
					companyName: this.userInfo.companyName,
					id : this.userInfo.userId
				};
				api.httpRequest('/wechat/user/saveUser',data,enums.enums.REQUEST_METHOD.POST).then(res => {
				    if (res.code == '200') {
				    	that.$store.dispatch('update_user_info', this.userInfo);
				    	uni.navigateBack({
                           delta: 1,
						   success:function() {
						   	// 返回成功后重新加载页面
						   	var pages = getCurrentPages();
						   	let page = pages[pages.length - 1];
						   	if (page == undefined || page == null) return;
						   	if (that.backUrl !== '/pages/my/index') {
						   		page.onLoad();
						   	}
						  }
                        });
						that.showToast("保存成功", 3000);
					}else{
						// 显示错误提示语
						that.showToast(res.message);
					}
				})
			}
		}
	}
</script>

<style>
.page-body {
	background-color: #f2f2f5;
	width:100vw;
	min-height: 100vh;
	padding-top: 20upx;
	box-sizing: border-box;
	padding-bottom: 20upx;
}
.page-body-box{
	background:#F2F2F5;
	margin-left: 24upx;
	margin-right: 24upx;
	border-top: 1px #e5e5e5 solid;
	
}
.info-box{
	display: flex;
	height: 80upx;
	line-height: 80upx;
	vertical-align: middle;
	padding: 0 24upx;
	font-size: 28upx;
	color: #1a1a1a;
	background-color: #ffffff;
	border-bottom: 1px #e5e5e5 solid;
	align-items: center;
	justify-content: flex-start;

}
.info-row-text{
	height: 80upx;
	line-height: 80upx;
	padding-left: 24upx;
	font-size: 28upx;
	color: #1A1A1A;
	width: 220upx;
}
.info-row-input input{
	height: 88upx;
	line-height: 88upx;
	padding-right: 110upx;
}
.info-checkbox text{
	font-size: 28upx;
	color: #4C4C4C;
}
.page-userinfo-btn-box button {
	width: 580upx;
	background: #077131;
	color: #FFFFFF;
	font-size: 34upx;
	height: 80upx;
	line-height:80upx;
	text-align: center;
	border-radius: 44upx;
}
.page-userinfo-btn-submit-box {
	  text-align: center;
		height:68rpx;
		/* width:156rpx; */
		position:fixed;
		margin-top: 80rpx;
		left: 0;
		right: 0;
		
	}
</style>
